﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARControlLib
{
	/// <summary>
	/// MessageContainer.xaml 的交互逻辑
	/// </summary>
	public partial class MessageContainer : UserControl
	{
		public MessageContainer()
		{
			this.InitializeComponent();
		}

        private void SARScrollBar_SARScrollBarDragged(double radio)
        {
            double margintop = this.stackContent.ActualHeight - 84;
            stackContent.Margin = new Thickness(0, -margintop * radio, 0, 0);
        }

        public void SARAddText(string text)
        {
            TextBlock newText = new TextBlock();
            newText.Text = text;

            newText.Style = FindResource("SARTextStyle") as Style;
            this.stackContent.Children.Add(newText);
            this.stackContent.SizeChanged += new SizeChangedEventHandler(stackContent_SizeChanged);
        }

        void stackContent_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (this.stackContent.ActualHeight > 84)
            {
                this.scrollBar.IsEnabled = true;
                this.scrollBar.SARRadio = 1;
            }
        }

        private void gridContent_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            double delta = e.Delta / this.stackContent.ActualHeight/10;
            this.scrollBar.SARRadio -= delta;
        }
	}
}